<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:fragment="tale_comment">
<body>
<div th:replace="admin/header::headerFragment(title,active)"></div>
<script type="text/javascript">
    /*<![CDATA[*/
    (function () {
        window.TaleComment = {
            dom: function (id) {
                return document.getElementById(id);
            },
            create: function (tag, attr) {
                var el = document.createElement(tag);
                for (var key in attr) {
                    el.setAttribute(key, attr[key]);
                }
                return el;
            },
            reply: function (id) {
                $('#comment-form input[name=id]').val(id);
                $("html,body").animate({scrollTop: $('div.comment-container').offset().top}, 500);
                $('#comment-form #textarea').focus();
            },
            subComment: function () {
                var tale = new $.tale();
                console.log('进入提交函数')
                $.ajax({
                    type: 'post',
                    url: '/article/comment',
                    data: $('#comment-form').serialize(),
                    success: function (result) {
                        console.log('进入提交评论')
                        let articleId = $('#comment-form input[name=articleId]').val();
                        $('#comment-form input[name=id]').val('')
                        if (result.code == 200) {
                            tale.alertOk({
                                text:'评论已提交至后台审核',
                                then: function () {
                                    setTimeout(function () {
                                        window.location.href = "/article/toPost/"+articleId;
                                    }, 500);
                                }
                            });
                        } else if (result.code == 1001){
                            window.location.href = "/user/toLogin";
                        }else {
                            tale.alertError(result.msg)
                        }
                    }
                });
                return false;
            }
        };
    })();
/*    function getCommentCookie(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return unescape(decodeURI(arr[2]));
        else
            return null;
    }
    function addCommentInputValue() {
        document.getElementById('author').value = getCommentCookie('cache_author');
        document.getElementById('email').value = getCommentCookie('cache_email');
        document.getElementById('url').value = getCommentCookie('cache_url');
    }
    addCommentInputValue();*/
    /*]]>*/
</script>
</body>
</html>
